using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using BubzCommerce.CMS.Data.ManagerObjects;
using BubzCommerce.CMS.Data.BusinessObjects;
using BubzCommerce.CMS.Data.Base;

namespace BubzCommerce.CMS.Tests.Data
{
	[TestFixture]
    public partial class ZzCurrencyTests : UnitTestbase
    {
        [SetUp]
        public void SetUp()
        {
            manager = managerFactory.GetZzCurrencyManager();
            manager.Session.BeginTransaction();
        }

        [TearDown]
        public void TearDown()
        {
            manager.Session.RollbackTransaction();
            manager.Dispose();
        }
        
        protected BubzCommerce.CMS.Data.ManagerObjects.IZzCurrencyManager manager;
		
		protected BubzCommerce.CMS.Data.BusinessObjects.ZzCurrency CreateNewZzCurrency()
		{
			BubzCommerce.CMS.Data.BusinessObjects.ZzCurrency entity = new BubzCommerce.CMS.Data.BusinessObjects.ZzCurrency();
			
			
			entity.Name = "Test Test ";
			entity.Code = "Te";
			entity.IsActive = true;
			entity.Created = System.DateTime.Now;
			entity.Edited = System.DateTime.Now;
			
			return entity;
		}
		protected BubzCommerce.CMS.Data.BusinessObjects.ZzCurrency GetFirstZzCurrency()
        {
            IList<BubzCommerce.CMS.Data.BusinessObjects.ZzCurrency> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				BubzCommerce.CMS.Data.BusinessObjects.ZzCurrency entity = CreateNewZzCurrency();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                BubzCommerce.CMS.Data.BusinessObjects.ZzCurrency entityA = CreateNewZzCurrency();
				manager.Save(entityA);

                BubzCommerce.CMS.Data.BusinessObjects.ZzCurrency entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                BubzCommerce.CMS.Data.BusinessObjects.ZzCurrency entityA = GetFirstZzCurrency();
				
				entityA.Name = "Test Test ";
				
				manager.Update(entityA);

                BubzCommerce.CMS.Data.BusinessObjects.ZzCurrency entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Name, entityB.Name);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                BubzCommerce.CMS.Data.BusinessObjects.ZzCurrency entity = GetFirstZzCurrency();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

